<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
	public function index(){
		$map = array();
		if(isset($_GET['type'])){
			$map = array('type'=>intval(I('get.type')));
		}
		$articles = M('post')->where($map)->select();
		$this->assign('list',$articles);
		$this->display();
	}

	public function detail($id){
		$this->assign('info',M('post')->find($id));
		$this->display();
	}

	public function add(){
		if(IS_POST){
			if(!I('post.type')){
				c('DEFAULT_FILTER', '');
			}
			$model = D('Post');
			$data = $model->create();
			if(!$data){
				$this->error($model->getError());
			}
			if($model->add())
				$this->success('添加成功');
			else
				$this->error('添加失败');
		}
	}
}